package com.sl.biz.modular.print.service.impl;

import cn.hutool.core.util.StrUtil;
import com.sl.biz.modular.print.dao.domain.entity.PrintConfigDO;
import com.sl.biz.modular.print.dao.service.PrintConfigContentDaoService;
import com.sl.biz.modular.print.dao.service.PrintConfigDaoService;
import com.sl.biz.modular.print.service.PrintConfigBizService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class PrintConfigBizServiceImpl implements PrintConfigBizService {

    private final PrintConfigDaoService printConfigDaoService;


    private final PrintConfigContentDaoService printConfigContentDaoService;

    protected Boolean add(PrintConfigDO officeRecord) {
        return printConfigDaoService.save(officeRecord);
    }

    @Override
    public Boolean save(PrintConfigDO officeRecord) {
        String id = officeRecord.getId();
        if (StrUtil.isNotBlank(id)) {
            return updateById(officeRecord);
        }
        return add(officeRecord);
    }

    @Override
    public List<PrintConfigDO> list(PrintConfigDO jobConfigDO) {
        return printConfigDaoService.list(jobConfigDO);
    }

    @Override
    public PrintConfigDO getById(PrintConfigDO printConfigDO) {
        return printConfigDaoService.getById(printConfigDO.getId());
    }

    @Override
    public Boolean removeById(PrintConfigDO printConfigDO) {
        printConfigContentDaoService.removeByPrintId(printConfigDO.getId());
        printConfigDaoService.removeById(printConfigDO.getId());
        return Boolean.TRUE;
    }

    protected Boolean updateById(PrintConfigDO updateByIdRequest) {
        return printConfigDaoService.updateById(updateByIdRequest);
    }
}
